unit ChangePasswordForm;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
  System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs,
  FMX.StdCtrls, FMX.Edit, FMX.Objects, FMX.Effects, FMX.Controls3D, FMX.Layers3D, FMX.Viewport3D;

type
  TfrmChangePassword = class(TForm)
    StyleBook1: TStyleBook;
    Viewport3D1: TViewport3D;
    Layer3D1: TLayer3D;
    btnAnnulla: TCornerButton;
    ReflectionEffect3: TReflectionEffect;
    btnOK: TCornerButton;
    ReflectionEffect2: TReflectionEffect;
    edPassword2: TEdit;
    Label2: TLabel;
    edPassword1: TEdit;
    Label1: TLabel;
    Image1: TImage;
    ReflectionEffect1: TReflectionEffect;
    procedure btnOKClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure edPassword2KeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
  private
    procedure Squotitura;
  public
    { Public declarations }
  end;

var
  frmChangePassword: TfrmChangePassword;

implementation

uses
  ConnectionU;

{$R *.fmx}

procedure TfrmChangePassword.btnOKClick(Sender: TObject);
begin
  if (edPassword1.Text = edPassword2.Text) and (edPassword1.Text = '') then
    MessageDlg('E'' necessario impostare una password', TMsgDlgType.mtError, [TMsgDlgBtn.mbOK], 0)
  else
    if edPassword1.Text <> edPassword2.Text then
  begin
    Squotitura;
    edPassword2.SetFocus;
  end
  else
  begin
    if TGestioniFactory.GestioneUtenti.ModifyPassword(edPassword1.Text) then
    begin
      ModalResult := mrOK
    end
    else
      ModalResult := mrAbort;

  end;
end;

procedure TfrmChangePassword.edPassword2KeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
begin
  if Key = vkReturn then
    btnOKClick(self);
end;

procedure TfrmChangePassword.FormCreate(Sender: TObject);
begin
  Layer3D1.Opacity := 0;
end;

procedure TfrmChangePassword.FormShow(Sender: TObject);
begin
  edPassword1.SetFocus;
  Layer3D1.AnimateFloat('opacity', 1, 1);
end;

procedure TfrmChangePassword.Squotitura;
begin
  beep;
  Layer3D1.AnimateFloatWait('Position.x', 250, 0.1);
  Layer3D1.AnimateFloatWait('Position.x', 295, 0.1);
  Layer3D1.AnimateFloatWait('Position.x', 260, 0.1);
  Layer3D1.AnimateFloatWait('Position.x', 285, 0.1);
  Layer3D1.AnimateFloatWait('Position.x', 270, 0.1);
  Layer3D1.AnimateFloatWait('Position.x', 275, 0.1);
end;

end.
